/**
 * systemAdmin vuex
 */
import posts from '@/plugins/request'

// initial state
const state = {
  stationInstrument: [],
  filesType: [],
  auditList: []
}
// getters
const getters = {
  getStationInstrument: state => state.stationInstrument,
  getFilesType: state => state.filesType,
  getAuditList: state => state.auditList,
}
// actions

const actions = {
  async fetchStationInstrument({ commit }) {
    let data = await posts.fetchStationInstrument()

    let stationInstrument = []
    let fileTypes = []
    for(let i in data.nameList) {
      stationInstrument.push({
        station: i,
        instrument: data.nameList[i],
      })
    }
    for(let i in data.type) {
      fileTypes.push({
        label: data.type[i],
        value: i,
      })
    }
    commit('changeStationInstrument', stationInstrument)
    commit('changeFilesType', fileTypes)
  },
  async postSystemFiles(context, formdata) {
    let result = await posts.postSystemFiles(formdata)
    return result
  },
  async fetchAuditList({ commit }, formdata) {
    let data = await posts.fetchAuditList(formdata)
    commit('changeAuditList', data)
  },
  async postAuditUser(context, data) {
    let result = await posts.postAuditUser(data)
    return result
  },
}

// mutations
const mutations = {
  changeStationInstrument(state, data) {
    state.stationInstrument = data
  },
  changeFilesType(state, data) {
    state.filesType = data
  },
  changeAuditList(state, data) {
    state.auditList.length = 0
    for(let i = 0; i < data.length; i++) {
      state.auditList.push(Object.assign({}, data[i], { headImg: data[i].photo ? data[i].photo.split(',')[0] : "" }))
    }
  },
}


export default {
  state,
  getters,
  actions,
  mutations
}